<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Dreamer CMS - 后台登录</title>
    <link href="/resource/css/custom-login.css" rel="stylesheet" />
</head>

<body>
<canvas></canvas>
<div class="login">
	<h1>CMS System</h1>
	<form method="post" id="loginForm">
		<div class="login-form-row">
			<input id="username" type="text" name="username" placeholder="用户名" required="required" />
		</div>
		<div class="login-form-row">
			<input id="password" type="password" name="password" placeholder="密码" required="required" />
		</div>
		<div class="login-form-row">
			<button type="button" class="btn btn-primary btn-block btn-large" onclick="login();">登录</button>
		</div>
	</form>
</div>
<div class="copyright">Copyright © 2023 LGP  苏ICP备19126660号</div>
<script src="/resource/js/jquery.min.js"></script>
<script src="/resource/js/jsencrypt/jsencrypt.min.js"></script>
<script src="/resource/js/coco-message/coco-message.js"></script>
<script src="/resource/js/vector.js"></script>
<script>
	if (window.frames.length != parent.frames.length) {
		window.parent.location.href = "/cms/login";
	}
    $(function () {
    	$('#username').focus();

    	$("#loginForm").keyup(function(event){
    		if(event.keyCode ==13){
    			login();
    		}
    	});

	});


	// 登录
    function login(){
		var username = $("#username").val();
		var password = $('#password').val();

		var data = {
			username : username,
			password : password
		};
		$.ajax({
			url : "/cms/loginAction",
			contentType : 'application/json',
			data : JSON.stringify(data),
			type : "POST",
			dataType : "JSON",
			success : function(result) {
				if(result.code==200){
                    console.log(result)
					sessionStorage.setItem("dreamer-cms-user", JSON.stringify(result.data));
					setTimeout(function() {
						//登录返回
						window.location.href = "/cms";
					}, 500);
				}else{
					cocoMessage.error(result.msg);
				}
			}
		});
	}
</script>
</body>
</html>
